/* 
 * File:   VerticesWatcher.cpp
 * Author: Thomas Trojer
 * 
 * Created on 28. Oktober 2010, 22:29
 */

#include "VerticesWatcher.h"
#include <GL/gl.h>
#include <GL/glut.h>

VerticesWatcher::VerticesWatcher() {
}

VerticesWatcher::VerticesWatcher(const VerticesWatcher& orig) {
}

VerticesWatcher::~VerticesWatcher() {
}

void VerticesWatcher::look(TurtleState* oldState, TurtleState* newState, TurtleState* stateTrace) {
    mehari::common::Vec4f oldPos(*(oldState->getPosition()));
    mehari::common::Vec4f newPos(*(newState->getPosition()));

    //std::cout << "walked from (" << oldPos.x() << "," << oldPos.y() << oldPos.z() << ") to (" << ")" << std::endl;

    vertices.push(oldPos);
    vertices.push(newPos);

    render();
}

void VerticesWatcher::render() {
    glClearColor(0.0, 0.0, 0.0, 1.0); //clear the screen to black
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //clear the color buffer and the depth buffer

    glColor3f(1.0, 1.0, 1.0);
    glPushMatrix();

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glBegin(GL_LINES);

    for(int i = 0; i < vertices.size(); i++) {
        glVertex3f(vertices[i].x(), vertices[i].y(), vertices[i].z());
    }

    glEnd();

    glPopMatrix();

    glutSwapBuffers(); //swap the buffers
}

